package sspersonserver.db;

import sspersonserver.LoginData;
import sspersonserver.subjects.*;

import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: Double
 * Date: 30.01.12
 * Time: 14:28
 * To change this template use File | Settings | File Templates.
 */
public class DatabaseHandler implements IDB
{
	private IDB iDB;

	public DatabaseHandler()
	{
		
	}
	public void setDB(String dbType)
	{
		//iDB.disconnect();
		iDB = DatabaseFactory.getDatabase(dbType);
		iDB.connect("localhost","softserve_persona");
	}
	public IDB getDB()
	{
		return iDB;
	}
	
	@Override
	public ArrayList<Person> getPersonList()
	{
		return iDB.getPersonList();
	}

	@Override
	public ArrayList<Person> getPersonList(int startIndex, int endIndex)
	{
		return iDB.getPersonList(startIndex,endIndex);
	}

	@Override
	public ArrayList<Country> getCountry()
	{
		return iDB.getCountry();
	}

	@Override
	public ArrayList<City> getCity(int id)
	{
		return iDB.getCity(id);
	}

	@Override
	public ArrayList<Street> getStreet(int id)
	{
		return iDB.getStreet(id);
	}

	@Override
	public ArrayList<Address> getAddress()
	{
		return iDB.getAddress();
	}

	@Override
	public void addCountry(Country country)
	{
		iDB.addCountry(country);
	}

	@Override
	public void addCity(City city)
	{
		iDB.addCity(city);
	}

	@Override
	public void addStreet(Street street)
	{
		iDB.addStreet(street);
	}

	@Override
	public void removeCountry(Country country)
	{
		iDB.removeCountry(country);
	}

	@Override
	public void removeCity(City city)
	{
		iDB.removeCity(city);
	}

	@Override
	public void removeStreet(Street street)
	{
		iDB.removeStreet(street);
	}

	@Override
	public FullPerson getFullPerson(int id)
	{
		return iDB.getFullPerson(id);
	}

	@Override
	public void saveFullPerson(FullPerson fullPerson)
	{
		iDB.saveFullPerson(fullPerson);
	}

	@Override
	public void save(ArrayList<Person> persons)
	{
		iDB.save(persons);
	}

	@Override
	public void update(FullPerson fullPerson)
	{
		iDB.update(fullPerson);
	}

	@Override
	public void delete(FullPerson fullPerson)
	{
		iDB.delete(fullPerson);
	}

	@Override
	public int checkAuth(LoginData loginData)
	{
		return iDB.checkAuth(loginData);

	}

	@Override
	public void connect(String ip, String database)
	{
		iDB.connect(ip,database);
	}

	@Override
	public void disconnect()
	{
		iDB.disconnect();
	}
	@Override
	public ArrayList<PhoneType> getPhoneType()
	{
		return iDB.getPhoneType();
	}

	@Override
	public void addPhoneType(PhoneType phoneType)
	{
		iDB.addPhoneType(phoneType);
	}

	@Override
	public void removePhoneType(PhoneType phoneType)
	{
		iDB.removePhoneType(phoneType);
	}
}
